﻿<link rel="stylesheet" type="text/css" href="<?php echo base_url('common/home')?>/css/style.css" />
<script type="text/javascript" src="<?php echo base_url('common/home')?>/js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/layer/layer.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.Msg.js"></script>
<!--<script src="../../../../common/home/js/jquery-1.10.2.js"></script>-->
<script type="text/javascript">
    $(function () {
        var index = parent.layer.getFrameIndex(window.name);
        $(".closeCart").click(function () {
            parent.layer.close(index);
        });
    })
    function vp_url(url) {
        parent.location.href = url;

    }
    function format_money(price) {
        return Math.floor(parseFloat(price * 100)) / 100;
    }
    function del_cart(carid) {
        var backurl = window.location.href;
        var url = '<?php echo site_url('cart/del_cart')?>';
        $.post(url, { 'cartid': carid, 'backurl': backurl }, function (data) {
            var jsonData = $.parseJSON(data);
            if (jsonData.Statu == 'ok') {
                var old_count = parseInt(parent.$(".logoAndLogin .cart").find('span').text());
                //alert(parent.$(".logoAndLogin .cart").find('span').text());
                parent.$(".logoAndLogin .cart").find('span').text(old_count - 1)
                $.Success(jsonData);
            } else {
                $.Success(jsonData);
            }
        });
    }

    function add_count(cart_id) {

        var old_val = parseInt($(".cart_item_count_" + cart_id).val());
        var new_val = old_val + 1;

        var url = '<?php echo site_url('cart/update_cart_count')?>';
            $.post(url, { 'cartid': cart_id, 'new_val': new_val,'backurl':parent.window.location.href }, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    $(".cart_item_count_" + cart_id).val(new_val);
                    var shop_price = format_money($('.cart_price_' + cart_id).attr('shop_price'));
                    var talprice = shop_price * parseInt(new_val);
                    $('.cart_tal_price_' + cart_id).text('￥' + talprice);
                    $.Success(jsonData);
                } else {
                    $.Success(jsonData);
                }
            });
    }
    function reduce_count(cart_id) {
        var old_val = parseInt($(".cart_item_count_" + cart_id).val());
        var new_val = 1;
        if (old_val > 1) {
            new_val = old_val - 1;
        }
        if (old_val != new_val) {
            
            var url = '<?php echo site_url('cart/update_cart_count')?>';
            $.post(url, { 'cartid': cart_id, 'new_val': new_val, 'backurl': parent.window.location.href }, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    $(".cart_item_count_" + cart_id).val(new_val);
                    var shop_price = format_money($('.cart_price_' + cart_id).attr('shop_price'));
                    var talprice = shop_price * parseInt(new_val);
                    $('.cart_tal_price_' + cart_id).text('￥' + talprice);
                    $.Success(jsonData);
                } else {
                    $.Success(jsonData);
                }
            });
        }
    }
</script>
<div class="hCartMask" style="display:block;">
    <div class="w794" style="margin:0 auto 0;">
        <h1>购物车</h1>
        <img class="closeCart" src="<?php echo base_url('common/home')?>/img/hClose.png" width="22" height="21" alt="">
        <div class="clearfix"></div>

        <!--登录提示 begin-->
        <!--购物车列表 begin-->
        <div class="cartLists">
            <div class="cartListsTitle">

                <div class="w191">商品</div>
                <div class="w141">属性</div>
                <div class="w111">单价（元）</div>
                <div class="w109">数量</div>
                <div class="w115">小计（元）</div>
                <div class="w55">操作</div>
            </div>
            <?php foreach($goodscarts as $goodscartitem):?>
            <div class="cartListBar clearfix">
                <!--thumbnail_img-->
                <div class="w191_2">
                    <a href="javascript:vp_url('<?php echo site_url('goods/details/'.$goodscartitem->goods_id)?>')">
                        <img src="<?php echo base_url('').$goodscartitem->thumbnail_img?>" width="55" height="79" alt="">
                        <div><?php echo $goodscartitem->goodstitle?></div>
                    </a>
                </div>
                <div class="w141_2">
                    <div class="w141_2Con">
                        颜色分类：<?php echo $goodscartitem->title?><br>
                        尺寸：<?php echo $goodscartitem->sizetitle?>
                    </div>
                </div>
                <div class="w111_2 cart_price_<?php echo $goodscartitem->goods_cart_id?>" shop_price="<?php echo $goodscartitem->shop_price?>">￥<?php echo $goodscartitem->shop_price?></div>
                <div class="w109_2">
                    <span onclick="reduce_count('<?php echo $goodscartitem->goods_cart_id?>')" class="gMinus">-</span>
                    <span class="gCount"><input class="cart_item_count_<?php echo $goodscartitem->goods_cart_id?>" type="text" value="<?php echo $goodscartitem->count?>"></span>
                    <span onclick="add_count('<?php echo $goodscartitem->goods_cart_id?>')" class="gAdd">+</span>
                </div>
                <div class="w115_2 cart_tal_price_<?php echo $goodscartitem->goods_cart_id?>">￥<?php echo $goodscartitem->shop_price*$goodscartitem->count?></div>
                <a class="w55_2" href="javascript:vp_url('<?php echo site_url( "order/to_order/".$goodscartitem->goods_cart_id)?>')">结账</a>
                <a class="w55_2" href="javascript:del_cart('<?php echo $goodscartitem->goods_cart_id?>')">删除</a>
            </div>
            <?php endforeach;?>

        </div>
        <!--购物车列表 end-->

        <div class="w794Bottom">

            <a class="continueBuy" style="float:right;margin-right:18px;" href="javascript:vp_url('<?php echo site_url('shop/index')?>')">继续购物</a>

        </div>
    </div>


</div>